package edu.uis.csc478.spring09.threeoxen.persistence.store.impl;

import edu.uis.csc478.spring09.threeoxen.persistence.store.StoreRepository;
import edu.uis.csc478.spring09.threeoxen.persistence.store.GroceryItem;
import edu.uis.csc478.spring09.threeoxen.persistence.store.InventoryItem;
import edu.uis.csc478.spring09.threeoxen.persistence.store.Store;
import edu.uis.csc478.spring09.threeoxen.persistence.BaseRepository;
import edu.uis.csc478.spring09.threeoxen.persistence.pantry.Pantry;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Collection;

public class StoreRepositoryImpl extends BaseRepository implements StoreRepository {

    private HashMap groceryItems = new HashMap();
    private HashMap stores = new HashMap();
    private HashMap pantries = new HashMap();

    StoreRepositoryImpl() {
        
    }

    @Override
    public GroceryItem getGroceryItem(String itemId) {
        return (GroceryItem) this.groceryItems.get(itemId);
    }

    @Override
    public void addGroceryItem(GroceryItem item) {
        this.groceryItems.put(item.getUpcCode(), item);
    }

    @Override
    public void updateGroceryItem(GroceryItem item) {
        this.groceryItems.put(item.getUpcCode(), item);
    }

    @Override
    public void removeGroceryItem(String upcCode) {
        this.groceryItems.remove(upcCode);
    }

    @Override
    public boolean groceryItemExists(String upcCode) {
        return this.groceryItems.get(upcCode) != null;
    }

    @Override
    public String getGroceryItemContents() {
        StringBuffer buffer = new StringBuffer();
        Collection entries = this.groceryItems.values();
        Iterator i = entries.iterator();
        GroceryItem item = null;
        while(i.hasNext()) {
            item = (GroceryItem) i.next();
            buffer.append(item.toString()).append("\n");
        }
        return buffer.toString();
    }

    @Override
    public Store getStoreByOwnerName(String storeOwnerName) {
        return (Store) this.stores.get(storeOwnerName);
    }

    @Override
    public void addStore(Store store) {
        this.stores.put(store.getStoreOwnerName(), store);
    }

    @Override
    public boolean storeExists(String storeOwnerName) {
        return this.stores.get(storeOwnerName) != null;
    }

}
